<?php
namespace Fiestissima\CRM\Controller;

use Fiestissima\CRM\Entity\Precio;
use Fiestissima\CRM\Form\Type\PrecioType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ProductosController extends Controller
{
	public function indexAction()
	{
		$repository = $this->getDoctrine()->getRepository('FiestissimaCRM:Producto', 'fiestissima');
		// find *all* products
		// using findby so we can sort them (second param)
		$products = $repository->findBy(array(), array('pr_nombre' => 'ASC'));
		return $this->render('FiestissimaCRM:Default:productos.html.php', array('products' => $products));
	}

	public function typeAction($type)
	{
		$repository = $this->getDoctrine()->getRepository('FiestissimaCRM:ProductoTipo', 'fiestissima');
		
		$getType = $repository->findBy(array('tipo_nombre'=> $type));
		
		$prodRepo = $this->getDoctrine()->getRepository('FiestissimaCRM:Producto', 'fiestissima');
		$productos = $prodRepo->findBy(array('type' => $getType[0]->getTipoId()), array('pr_nombre' => 'ASC'));

		return $this->render('FiestissimaCRM:Default:productos.html.php', array('productos' => $productos, 'type' => $type));
	}
	
}